package com.example.showlocation.adapter

import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.CompoundButton
import android.widget.RadioButton
import android.widget.TextView
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import com.example.showlocation.R

class ItemAdapter_Kotlin(
    private val context: Context,
    val myDataset: Array<Array<String>>,
    val onCheckedChangeListener: CompoundButton.OnCheckedChangeListener
) : RecyclerView.Adapter<ItemAdapter_Kotlin.ItemViewHolder>() {
    class ItemViewHolder(private val view: View) : RecyclerView.ViewHolder(view) {
        val textView11: TextView = view.findViewById(R.id.textView11)
        val textView12: TextView = view.findViewById(R.id.textView12)
        val textView13: TextView = view.findViewById(R.id.textView13)
        val radioButton: RadioButton = view.findViewById(R.id.radioButton)
    }
    /**
     * Create new views (invoked by the layout manager)
     */
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {
        // create a new view
        val adapterLayout = LayoutInflater.from(parent.context)
            .inflate(R.layout.list_item, parent, false)
        return ItemViewHolder(adapterLayout)
    }

    override fun getItemCount(): Int {
       return myDataset.size

    }

    /*
      Replace the contents of a view (invoked by the layout manager)
     */
    override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {
        holder.textView11.text = myDataset[position][0]
        if ( position== 0) {
            holder.radioButton.isVisible=true
            holder.radioButton.setOnCheckedChangeListener(onCheckedChangeListener)
        } else {
            holder.textView12.text = myDataset[position][1]
            holder.textView13.text = myDataset[position][2]+"meters"
        }
        myDataset[position][0]?.let { Log.d("ItemAdapter:", it) }
        myDataset[position][1]?.let { Log.d("ItemAdapter:", it) }
    }
    /**
     * Return the size of your dataset (invoked by the layout manager)
     */
}

